package ${package.Controller};

import com.alibaba.cola.dto.Query;
import com.baoyouqun.base.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.baoyouqun.domain.VO.${entity}VO;
import com.baoyouqun.domain.CreateCmd.${entity}CreateCmd;
import com.baoyouqun.domain.UpdateCmd.${entity}UpdateCmd;
import com.baoyouqun.domain.Query.${entity}Query;

@RestController
@RequestMapping("/${entity?uncap_first}")
@Api(tags = "${table.comment}管理接口")
public class ${entity}Controller {

    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @PostMapping("create")
    @ApiOperation("新增${table.comment}")
    public SingleResponse<${entity}VO> create(@Valid @RequestBody ${entity}CreateCmd cmd) {
        return ${table.serviceName?uncap_first}.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改${table.comment}")
    public Response update(${entity}UpdateCmd cmd) {
        return ${table.serviceName?uncap_first}.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除${table.comment}")
    public Response delete(String id) {
    ${table.serviceName?uncap_first}.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询${table.comment}")
    public SingleResponse<${entity}VO> selectById(String id) {
        return SingleResponse.of(${table.serviceName?uncap_first}.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询${table.comment}")
    public PageResponse<${entity}VO> page(${entity}Query query) {
        IPage<${entity}VO> page = ${table.serviceName?uncap_first}.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}